<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link rel="stylesheet" type="text/css" href="/static/Admin/plugins/colorpicker/colorpicker.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/custom-plugins/wizard/wizard.css" media="screen">

    <!-- Required Stylesheets -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/bootstrap/css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/fonts/ptsans/stylesheet.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/fonts/icomoon/style.css" media="screen">

    <link rel="stylesheet" type="text/css" href="/static/Admin/css/mws-style.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/icons/icol16.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/icons/icol32.css" media="screen">

    <!-- Demo Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/demo.css" media="screen">

    <!-- jQuery-UI Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/jui/css/jquery.ui.all.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/jui/jquery-ui.custom.css" media="screen">

    <!-- Theme Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/mws-theme.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/themer.css" media="screen">

    <!-- 引入 layui -->
    <script src="/static/layui/layui.all.js"></script>
    <link rel="stylesheet" href="/static/layui/css/layui.css">

</head>

<body>

    <div class="mws-panel grid_8">
        <div class="mws-panel-header" style="height: 49px">
            <span>
                <i class="icon-table"></i> 订单列表</span>
        </div>
        <div class="mws-panel-body no-padding">
            <div id="DataTables_Table_1_wrapper" class="dataTables_wrapper" role="grid">
                <!--
                <div id="DataTables_Table_1_length" class="dataTables_length">
                    <a href="/order/Excel" class="btn btn-info" id="excel">导出全部订单Excel文件</a>
                </div>
             -->
                <form action="/order/OrderList" method="get">
                    <div class="dataTables_length">
                        按照时间段搜索
                        <select name="search_type_of_time" id="">
                            <option value="" {if condition="$search_type_of_time == ''" } selected {/if}>--选择时间段--</option>
                            <option value="1" {if condition="$search_type_of_time == '1'" } selected {/if}>下单时间</option>
                            <option value="2" {if condition="$search_type_of_time == '2'" } selected {/if}>发货时间</option>
                            <option value="3" {if condition="$search_type_of_time == '3'" } selected {/if}>收货时间</option>
                        </select>
                    </div>

                    <div class="dataTables_length">
                        <input type="text" class="layui-input" id="atime" name="atime" value="{$atime}">
                    </div>
                    <div class="dataTables_length">
                        <input type="text" class="layui-input" id="ztime" name="ztime" value="{$ztime}">
                    </div>
                    <div class="dataTables_filter" id="DataTables_Table_1_filter">
                        <label>订单编号:
                            <input type="text" aria-controls="DataTables_Table_1" name="keyword" value="{$keyword}">
                            <input type="submit" class="btn btn-info">
                        </label>
                    </div>
                </form>

                <table class="mws-datatable-fn mws-table dataTable" id="DataTables_Table_1" aria-describedby="DataTables_Table_1_info">
                    <thead>
                        <tr role="row">
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 200px;" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column ascending">编号</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 100px;" aria-label="Platform(s): activate to sort column ascending">订单号</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 100px;" aria-label="Platform(s): activate to sort column ascending">用户名</th>
                           <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 150px;" aria-label="Platform(s): activate to sort column ascending">手机号</th>
                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 200px;" aria-label="Platform(s): activate to sort column ascending"
                                id="add_time" data-type="{$order_type}" style="cursor:pointer;">下单时间</th>
                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 100px;" aria-label="Platform(s): activate to sort column ascending"
                                id="delivery_time" data-type="{$order_type}">发货时间</th>
                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 100px;" aria-label="Platform(s): activate to sort column ascending"
                                id="receive_time" data-type="{$order_type}">收货时间</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 300px;" aria-label="Platform(s): activate to sort column ascending">收货地址</th>

                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 200px;" aria-label="Platform(s): activate to sort column ascending">商品信息</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 50px;" aria-label="Platform(s): activate to sort column ascending">商品总数</th>

                            <!--
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 100px;" aria-label="Platform(s): activate to sort column ascending">是否使用优惠</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 100px;" aria-label="Platform(s): activate to sort column ascending">优惠金额</th>
                            -->
                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 100px;" aria-label="Platform(s): activate to sort column ascending"
                                id="nominal_amount" >应付金额</th>
                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 100px;" aria-label="Platform(s): activate to sort column ascending"
                                id="actual_amount">实付金额</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1"  aria-label="Platform(s): activate to sort column ascending">
                                <select name="status" id="js_status">
                                    <option value="0" {if condition="$status == '0'" }selected{/if}>--状态--</option>
                                    <option value="1" {if condition="$status == '1'" }selected{/if}>--未付款--</option>
                                    <option value="2" {if condition="$status == '2'" }selected{/if}>--未发货--</option>
                                    <option value="3" {if condition="$status == '3'" }selected{/if}>--已发货--</option>
                                    <option value="4" {if condition="$status == '4'" }selected{/if}>--已完成--</option>
                                    <option value="5" {if condition="$status == '5'" }selected{/if}>--已取消--</option>
                                </select>
                            </th>
                            <!--
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1"  aria-label="Platform(s): activate to sort column ascending">操作</th>
                           -->
                        </tr>
                    </thead>

                    <tbody>
                        {foreach name="list" item="vo"}
                        {php}$vo = \app\admin\model\OrderModel::handleOrderInfo($vo){/php}

                        <tr class="gradeA odd">
                            <td class="">{$vo.order_info_id}</td>
                            <td class="">{$vo.order_sn}</td>
                            <td class="">{$vo.user_name}</td>
                           <td class="">{$vo.user_phone}</td>
                            <td class="">
                                 {if condition="$vo.add_time == ''"} -- -- {else /} {$vo.add_time} {/if}
                            </td>
                            <td class="">
                                {if condition="$vo.delivery_time == ''"}
                                -- --
                                {else /}
                                {$vo.delivery_time}
                                {/if}
                            </td>
                            <td class="">
                                 {if condition="$vo.receive_time == ''"} -- -- {else /} {$vo.receive_time} {/if}
                            </td>
                            <td class="">{$vo.address}</td>
                            <td class="">{$vo.goods_info}</td>
                            <td class="">{$vo.num}</td>

                            <!--
                            <td class="">
                                {if condition="($vo.is_coupon == 1)"} 是 {else / } 否 {/if}
                            </td>
                            <td class=" ">{$vo.coupon_sum}</td>
                            -->
                            <td class=" ">{$vo.nominal_amount}</td>
                            <td class=" ">{$vo.actual_amount}</td>

                            <td class="goodsStatus" >

                                {eq name="vo.status" value="4"}
                                已完成
                                {else}
                                   {eq name="vo.status" value="5"}
                                    已取消
                                   {else}
                                      <select name="order_status" class="js_order_status" data-id="{$vo.order_info_id}">
                                          <option value="1" {eq name="vo.status" value="1"}selected {/eq} >未付款</option>
                                          <option value="2" {eq name="vo.status" value="2"}selected {/eq} >未发货</option>
                                          <option value="3" {eq name="vo.status" value="3"}selected {/eq} >已发货</option>
                                          <option value="4" >已完成</option>
                                          <option value="5" >已取消</option>
                                      </select>
                                   {/eq}
                                {/eq}

                            </td>
                            <!--
                            <td>

                                {if condition="$vo.status == 2 "}
                                <a href="javascript:;" class="btn btn-info sendConfirm btn-sm" name="{$vo.order_id}">确认发货</a>
                                {else /}
                                -- 
                                {/if}

                            </td>
                            -->
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                <div class="" id="DataTables_Table_1_paginate" style="text-align: center">
                    {$list->render()}
                </div>
            </div>
        </div>
    </div>




</body>
<!-- JavaScript Plugins -->
<script src="/static/Admin/js/libs/jquery-1.8.3.min.js"></script>
<script src="/static/Admin/js/libs/jquery.mousewheel.min.js"></script>
<script src="/static/Admin/js/libs/jquery.placeholder.min.js"></script>
<script src="/static/Admin/custom-plugins/fileinput.js"></script>

<!-- jQuery-UI Dependent Scripts -->
<script src="/static/Admin/jui/js/jquery-ui-1.9.2.min.js"></script>
<script src="/static/Admin/jui/jquery-ui.custom.min.js"></script>
<script src="/static/Admin/jui/js/jquery.ui.touch-punch.js"></script>

<!-- Plugin Scripts -->
<script src="/static/Admin/plugins/datatables/jquery.dataTables.min.js"></script>
<!--[if lt IE 9]>
        <script src="js/libs/excanvas.min.js"></script>
        <![endif]-->
<script src="/static/Admin/plugins/flot/jquery.flot.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.tooltip.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.pie.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.stack.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.resize.min.js"></script>
<script src="/static/Admin/plugins/colorpicker/colorpicker-min.js"></script>
<script src="/static/Admin/plugins/validate/jquery.validate-min.js"></script>
<script src="/static/Admin/custom-plugins/wizard/wizard.min.js"></script>

<!-- Core Script -->
<script src="/static/Admin/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/Admin/js/core/mws.js"></script>

<!-- Themer Script (Remove if not needed) -->
<script src="/static/Admin/js/core/themer.js"></script>

<!-- Demo Scripts (remove if not needed) -->
<script src="/static/Admin/js/demo/demo.dashboard.js"></script>


<script>
    // 排序
    $("#add_time").click(function () {
        var order_type = $(this).attr('data-type');

        order_type = order_type == 1 ? 2 : 1;
        
        keyword = "{$keyword}" != '' ? "{$keyword}" : '';
        search_type_of_time = "{$search_type_of_time}" != '' ? "{$search_type_of_time}" : '';
        atime = "{$atime}" != '' ? "{$atime}" : '';
        ztime = "{$ztime}" != '' ? "{$ztime}" : '';

        var options = {
            url: "__WebSite__/order/OrderList",
            paramName: "order_type",
            newValue: order_type,
            keyword: keyword,
            search_type_of_time: search_type_of_time,
            atime: atime,
            ztime: ztime
        };
        location.href = generateURL(options);
    });
    $("#delivery_time").click(function () {
        var order_type = $(this).attr('data-type');

        order_type = order_type == 3 ? 4 : 3;
        
        keyword = "{$keyword}" != '' ? "{$keyword}" : '';
        search_type_of_time = "{$search_type_of_time}" != '' ? "{$search_type_of_time}" : '';
        atime = "{$atime}" != '' ? "{$atime}" : '';
        ztime = "{$ztime}" != '' ? "{$ztime}" : '';

        var options = {
            url: "__WebSite__/order/OrderList",
            paramName: "order_type",
            newValue: order_type,
            keyword: keyword,
            search_type_of_time: search_type_of_time,
            atime: atime,
            ztime: ztime
        };
        location.href = generateURL(options);
    });
    $("#receive_time").click(function () {
        var order_type = $(this).attr('data-type');

        order_type = order_type == 5 ? 6 : 5;

        keyword = "{$keyword}" != '' ? "{$keyword}" : '';
        search_type_of_time = "{$search_type_of_time}" != '' ? "{$search_type_of_time}" : '';
        atime = "{$atime}" != '' ? "{$atime}" : '';
        ztime = "{$ztime}" != '' ? "{$ztime}" : '';

        var options = {
            url: "__WebSite__/order/OrderList",
            paramName: "order_type",
            newValue: order_type,
            keyword: keyword,
            search_type_of_time: search_type_of_time,
            atime: atime,
            ztime: ztime
        };
        location.href = generateURL(options);
    });
//    $("#nominal_amount").click(function () {
//        var order_type = $(this).attr('data-type');
//
//        order_type = order_type == 7 ? 8 : 7;
//        keyword = "{$keyword}" != '' ? "{$keyword}" : '';
//        search_type_of_time = "{$search_type_of_time}" != '' ? "{$search_type_of_time}" : '';
//        atime = "{$atime}" != '' ? "{$atime}" : '';
//        ztime = "{$ztime}" != '' ? "{$ztime}" : '';
//
//        var options = {
//            url: "__WebSite__/order/OrderList",
//            paramName: "order_type",
//            newValue: order_type,
//            keyword: keyword,
//            search_type_of_time: search_type_of_time,
//            atime: atime,
//            ztime: ztime
//        };
//        location.href = generateURL(options);
//    });
//
//    $("#actual_amount").click(function () {
//        var order_type = $(this).attr('data-type');
//
//        order_type = order_type == 9 ? 10 : 9;
//
//        keyword = "{$keyword}" != '' ? "{$keyword}" : '';
//        search_type_of_time = "{$search_type_of_time}" != '' ? "{$search_type_of_time}" : '';
//        atime = "{$atime}" != '' ? "{$atime}" : '';
//        ztime = "{$ztime}" != '' ? "{$ztime}" : '';
//
//        var options = {
//            url: "__WebSite__/order/OrderList",
//            paramName: "order_type",
//            newValue: order_type,
//            keyword: keyword,
//            search_type_of_time: search_type_of_time,
//            atime: atime,
//            ztime: ztime
//        };
//        location.href = generateURL(options);
//    });

    $(".js_order_status").change(function () {

        var infoID = $(this).attr('data-id');
        var status = $(this).val();

        $.post("__WebSite__/order/ajaxChangeStatus",{id:infoID,status:status},function (data) {

            if(data['status'])
            {
                alert('操作成功')
            }else{
                alert('操作失败： '+ data['msg']);
            }
        },'json')
    })
</script>


<script type="text/javascript">
    var generateURL = function (options) {
        var url = options.url;
        var keyword = options.keyword;
        var search_type_of_time = options.search_type_of_time;
        var atime = options.atime;
        var ztime = options.ztime;


        if (search_type_of_time != '') {
            if ("/" != url[url.length - 1]) {
                url += "/";
            }
            url += 'search_type_of_time/' + search_type_of_time;
        }
        if (atime != '') {
            if ("/" != url[url.length - 1]) {
                url += "/";
            }
            url += 'atime/' + atime;
        }
        if (ztime != '') {
            if ("/" != url[url.length - 1]) {
                url += "/";
            }
            url += 'ztime/' + ztime;
        }
        if (keyword != '') {
            if ("/" != url[url.length - 1]) {
                url += "/";
            }
            url += 'keyword/' + keyword;
        }
        if (-1 == url.indexOf(options.paramName)) {
            if ("/" != url[url.length - 1]) {
                url += "/";
            }
            url += options.paramName + "/" + options.newValue;
        } else {
            var re = new RegExp(options.paramName + "/\\d+");
            url = url.replace(re, options.paramName + "/" + options.newValue);
        }
        // url = url.replace(/[=?&]/g, "/");
        return url;
    };
</script>


<!-- 时间插件 选择 -->
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#atime' //指定元素
        });
    });

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#ztime' //指定元素
        });
    });
</script>
<!-- 发货确定 -->
<script>
    $('.sendConfirm').on('click',function () {

        var res=window.confirm('确认发货');
        var order_id = $(this).attr('name');

        me=$(this);
        if(res){
            $.ajax({
                url: '/order/AjaxSendConfirm',
                data: { 'order_id': order_id },
                type: 'post',
                success: function (data) {
                    if(data == '4'){
                        me.parent('td').prev().html('已发货');

                        me.parent('td').html('<a href="javascript:;" class="btn btn-success " disabled>已发货</a>');
                    }else{
                        alert('操作失败');
                    }
                }
            })
        }
        
    })
    
</script>

<!-- 状态切换 -->
<script>
    var args = {
        status : "{$status}",
    };


    var keyword = "{$keyword}";
    if (keyword.length > 0) {
        args.keyword = keyword;
    }

    var search_type_of_time="{$search_type_of_time}";
    if (search_type_of_time != '') {
            args.search_type_of_time = search_type_of_time;
        }

    var atime = "{$atime}";
    if (atime != '') {
        args.atime = atime;
    }

    var ztime = "{$ztime}";
        if (ztime != '') {
            args.ztime = ztime;
        }

    function generateArgsStr() {
        var str = ""
        for (var name in args) {
            if (str.length == 0) {
                str = name + "/" + args[name];
            } else {
                str += "/" + name + "/" + args[name];
            }
        }
        return str;
    }
    var url = '__WebSite__/order/OrderList';

    $("#js_status option[value=" + args.status + "]").prop("selected", "selected");

    $("#js_status").on('change', function () {

        var val = $(this).val();

        console.log(val);

        args.status = val;
        url += "/" + generateArgsStr();
        console.log(url);
        location.href = url;
    })
</script>
</html>